package service

import (
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
	"log"
	"net/http"
	"path/filepath"
	"strings"
)

func UploadFile(c *gin.Context) {
	// 文件
	file, _ := c.FormFile("file")
	etc := strings.ToLower(filepath.Ext(file.Filename))

	if !strings.Contains(".mp4.avi.mkv", etc) {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "格式仅支持.mp4.avi.mkv",
		})
		return
	}

	if file.Size > 1024*1024*1024*5 {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "单个视频文件最大支持5GB",
		})
		return
	}

	file.Filename = uuid.NewString() + etc

	log.Println(file.Filename)
	url := "./file" + file.Filename

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "上传成功",
		"data": url,
	})
}
